/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
  BlobInputList, CCell, Cell, Table, TableBody, TableRow, Text, TextArea,
} from "customize-easy-ui-component";
import {CCellUnit, InspectRecordLayout, InternalItemProps, RepLink, useItemInputControl,} from "../../common/base";
import {usePrefixDataTable} from "../../hook/usePrefixData";
import {useMeasureInpFilter} from "../../common/hooks";
import {FootMenRow} from "../../contain/rarelyVary";
import {安全状况等级} from "../../../device/edit/容器";

export const config料审查 = [
  [['设计单位', '_$设计单位'], ],
  [['产品标准', '_$产品标准',], ['设计日期', '_$设计日期']],
  [['容器图号', '_$设计图号',], ['设计使用年限', '_$设计年限', '年']],
  [['制造单位', '_$制造单位'], ],
  [['制造日期', '_$制造日期'], ['产品编号', '_$出厂编号'], ],
  [['安装单位', '_$安装单位'], ],
  [['投入使用日期', '_$投用日期'],  ['上次检验日期', {n:'上检日',t:'d'} ],  ],
  [['设备代码', '_$设备代码'], ['使用登记证编号', '_$使用证号']],
  [[{pr: '结构型式', span: 2, t: '主体结构型式'}, '_$主体结构' ], ['安装型式', '_$安装型式'] ],
  [[{t: '支座型式'}, '_$支座型式'],   ['保温绝热方式', '_$保温绝热方式'] ],
  //性能参数：拆分点：
  [['总容积', '_$容积换热', 'm³'], ['瓶体外径', {n:'_$瓶外径', u:'mm'}],  ],
  [['高/长', '_$外形高长','mm'], ['最大充许充装量', {n:'_$允许充装量',u:'kg'},] ],
  [['设计压力', '_$设计压力', 'MPa'], ['工作压力', '_$工作压力', 'MPa'] ],
  [['设计温度',{n:'_$设计温', u:'℃'}], ['工作温度', '_$工作温度', '℃'],  ],
  [['腐蚀裕度', '_$腐蚀裕量', 'mm'], ['充装介质', '_$工作介质',],  ],
    //台账的？ 筒体 厚度；
  [['主体材质-瓶体', '瓶材质'], ['主体材质-端塞', '端材质'] ],
  [['瓶体厚度', {n:'瓶体厚', u:'mm'}], ],
];
const  问题选=['1、上次定期检验（2021011RD0007）由机械工业上海蓝亚石化设备检测有限公司实施。\n' +
    '2、Pw=25MPa，Tw=-40~60℃，介质： 天然气。',
];
const  资审选=['产品质量证明书、使用证、管理制度、操作规程、运行记录、应急预案，未见其它资料。',];
export const itemA料审查=['资审情','上次安级', '上次问题' ];
//不用：台账字段 pa?.安全;
export const MaterialReviewRes =
    React.forwardRef(({ children, show ,alone=true,refWidth,redId,nestMd,label}:InternalItemProps,  ref
    ) => {
      const [getInpFilter]=useMeasureInpFilter(null,itemA料审查, );
      const {inp, setInp} = useItemInputControl({ ref,redId,nestMd });
      return (
          <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show} redId={redId}
                               nestMd={nestMd} alone={alone} label={label!}>
            <Text variant="h5">{label}:</Text>
            <Text variant="h5">资料审查情况：</Text>
            （可以参照宏观检验报告格式列出资料审查项日和内容、审查结果和备注等栏目，也可以直接表述 审查发现的问题项目和内容及其问题和变更情况）
            <BlobInputList value={inp?.资审情 || ''} rows={6} datalist={资审选}
                           onListChange={v => setInp({...inp, 资审情: v || undefined})}/>
            <Text variant="h5">上次定期检验安全状况等级评为：</Text>
            <BlobInputList value={inp?.上次安级 || ''} rows={1} datalist={安全状况等级}
                           style={{display: 'flex', width: '8rem',margin: 'auto'}}
                           onListChange={v => setInp({...inp, 上次安级: v || undefined})}/>
            <Text variant="h5">上次定期检验问题记载：</Text>
            注明上次定期检验报告编号，检验发现的缺陷及处理情况
            <BlobInputList value={inp?.上次问题 || ''} rows={6} datalist={问题选}
                           onListChange={v => setInp({...inp, 上次问题: v || undefined})}/>
          </InspectRecordLayout>
      );
});
const items料审1=config料审查.slice(0,8);
const items料审2=config料审查.slice(8,15);
/**拆解几行不规矩的布局；
 * */
export const MaterialReviewVw = ({orc, rep, op}: { orc: any, rep: any, op?: boolean }
) => {
  const renderUpper = usePrefixDataTable({config: items料审1, orc, rep, slash: true});
  const [_1,_2,...leftRow] = usePrefixDataTable({config: items料审2, orc, rep, slash: true,
              embed: { 2:  <CCell rowSpan={6}>性能参数</CCell>, }
          });
  return <>
    <div css={{"@media print": {paddingBottom: '4rem', pageBreakInside: 'avoid'}}}>
      <Text id='MaterialReview' variant="h2" css={{textAlign: 'center', marginTop: '1rem',
      }}>资料审查报告</Text>
      <div css={{display: 'flex', justifyContent: 'space-between'}}>
        <Text>使用证号：{orc?.使用证号}</Text>
        <Text>{op?'记录':'报告'}编号：{rep.isp.no}</Text>
      </div>
    </div>
    <Table fixed={  ["5%","7.3%","%","6.1%","8%","31%"]  }
               css={{borderCollapse: 'collapse',"@media print": {marginTop: '-4rem'} }} tight  miniw={800}>
      <TableBody>
        <RepLink rep={rep} tag={"MaterialReview"}>
          {renderUpper}
        </RepLink>
      </TableBody>
    </Table>
    <Table fixed={  ["4.6%","5.4%","12.1%","%","6.1%","8%","31%"] }
                  css={{borderCollapse: 'collapse',}} tight  miniw={800}>
      <TableBody>
        <RepLink rep={rep} tag={"MaterialReview"}>
          <TableRow>
            <CCell rowSpan={2} colSpan={2}>结构型式</CCell><CCell>主体结构型式</CCell><CCell>{orc?.主体结构 || '／'}</CCell>
            <CCell colSpan={2}>安装型式</CCell><CCell>{orc?.安装型式 || '／'}</CCell>
          </TableRow>
          <TableRow>
            <CCell>支座型式</CCell><CCell>{orc?.支座型式 || '／'}</CCell><CCell colSpan={2}>保温绝热方式</CCell><CCell>{orc?.保温绝热方式 || '／'}</CCell>
          </TableRow>
          {leftRow}
          <TableRow>
            <CCell split css={{padding:0}} colSpan={6}>
              <Table  fixed={ ["10%","7%","39%","12%","%"]  }
                           css={ {borderCollapse: 'collapse', height:'fill-available'} } tight  miniw={800}>
                <TableBody>
                  <RepLink rep={rep} tag={"MaterialReview"}>
                    <TableRow>
                      <CCell rowSpan={2}>主体材质</CCell><CCell>瓶体</CCell><CCell>{orc?.瓶材质 || '／'}</CCell>
                      <CCell rowSpan={2}>瓶体厚度</CCell><CCellUnit rowSpan={2} unit='mm'>{orc?.瓶体厚 || '／'}</CCellUnit>
                    </TableRow>
                    <TableRow>
                      <CCell>端塞</CCell><CCell>{orc?.端材质 || '／'}</CCell>
                    </TableRow>
                  </RepLink>
                </TableBody>
              </Table>
            </CCell>
          </TableRow>
        </RepLink>
      </TableBody>
    </Table>
    <Table fixed={ ["8.6%","%"] } css={{borderCollapse: 'collapse', }} tight  miniw={800}>
      <TableBody>
        <RepLink rep={rep} tag={"MaterialReviewRes"}>
          <TableRow><CCell>资料审查情况</CCell>
            <Cell><div css={{minHeight: '3rem', whiteSpace: 'pre-wrap'}}>
              {orc?.资审情 || '／'}
            </div></Cell>
          </TableRow>
          <TableRow><CCell>上次定期检验问题记载</CCell>
            <Cell>上次定期检验安全状况等级评为：{orc?.上次安级 || '／'}
              <div css={{minHeight: '3rem', whiteSpace: 'pre-wrap',marginTop: '0.4rem'}}>
              {orc?.上次问题 || '／'}
            </div></Cell>
          </TableRow>
        </RepLink>
      </TableBody>
        <FootMenRow span={2} orc={orc} rep={rep} href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/ProjectList#ProjectList`}/>
    </Table>
  </>;
};
